package main

import (
	"fmt"
	"sync"
	"time"
)

//基础控制协程关系 顺序问题
var cjob1 chan struct{} //控制启动信息
var cjobb2 chan struct{}
var wg *sync.WaitGroup

func job1() {
	fmt.Println("cjob1工作")
	time.Sleep(time.Second * 3)
	cjob1 <- struct{}{} //做完通知一枪头协程继续
}
func job2() {
	<-cjob1 //等待上一个任务处理结束
	fmt.Println("cjob2启动")
	time.Sleep(time.Second * 2)
	fmt.Println("cjob2完成任务")
	cjobb2 <- struct{}{}
}
func job3() {
	<-cjobb2
	fmt.Println("cjob3开始启动")
	time.Sleep(time.Second * 3)
	fmt.Println("cjob3完成")
}
func main() {
	cjob1 = make(chan struct{}, 1)
	cjobb2 = make(chan struct{}, 1)
	wg = &sync.WaitGroup{}
	wg.Add(3)
	go func() {
		defer wg.Done()
		job1()
	}()
	go func() {
		defer wg.Done()
		job2()
	}()
	go func() {
		defer wg.Done()
		job3()
	}()
	wg.Wait()
}
